using System;
using opt.Analysis.Graph;
using opt.Analysis.Graph.CallGraph.CallGraphVisitor;

namespace opt.lib.ClassIFE
{
	public class ClassCallGraphVisitor : IGraphVisit<ClassIFEArcInfo,ClassIFENodeInfo>
	{
		private GraphNode<ClassIFEArcInfo,ClassIFENodeInfo> _caller;
		private int _arc_index;
		private int _smallest;

		public GraphNode<ClassIFEArcInfo,ClassIFENodeInfo> Caller
		{
			get
			{
				return _caller;
			}
		}
		public int ArcIndex
		{
			get
			{
				return _arc_index;
			}
		}

		public ClassCallGraphVisitor()
		{
			_smallest = int.MaxValue;
		}

		public void Visit(GraphNode<ClassIFEArcInfo,ClassIFENodeInfo> node)
		{
			int arc_count = node.Count;
			int i;
			GraphNode<ClassIFEArcInfo,ClassIFENodeInfo> callee;
			int callee_code_size;
			for(i = 0;i < arc_count;i++)
			{
				callee = node[i].Next;
				callee_code_size = callee.Data.Code.Count;
				if((callee_code_size < _smallest) && (!node[i].Data.Deleted))
				{
					_caller = node;
					_arc_index = i;
					_smallest = callee_code_size;
				}
			}
		}
	}
}
